  <!-- Right side column. Contains the navbar and content of the page -->
            <aside class="right-side">                
                <!-- Content Header (Page header) -->
                <section class="content-header">
                    <h1>
                       Fiche de bien
                        <small>Control panel</small>
                    </h1>
                    <ol class="breadcrumb">
                        <li><a href="<?=site_url()?>"><i class="fa fa-dashboard"></i> Accueil</a></li>
                        <li >Dossier</li>
                        <li class="active">Biens</li>
                    </ol>
                </section>

                <!-- Main content -->
                <section class="content">
                     <div class="row">
						<div class="col-lg-12 col-xs-12">

                            <div class="box box-default">
                          	<div class="box-body">
                          	   <a href="<?=site_url()?>properties" class="btn btn-warning btn-sm pull-right"> <i class="fa fa-arrow-left"></i> retour</a>
                          	</div>
                          	<div class="clearfix"></div>
                          	<br>
                    	</div>
                    	</div>
                        <div class="col-lg-6 col-xs-12">
                            <div class="box box-primary">
                            
                            	 <?php if(isset($errors)){?>
                            	
                            	 <div class="box-header">
        <div class="alert alert-danger alert-dismissible" role="alert">
      
  <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
  <strong>Attentions!</strong> <ol><?foreach( $errors as $e ):?><li><?=$e?></li><?php endforeach;?></ol>
</div>
</div>
        <?php }?>
                    
                                <div class="box-body ">
                                	<div class="row">
                         			<div class="col-lg-12 col-xs-12">
                         				<div class="propertyInfo">
                         					<dl class="dl-horizontal">
                         						<dt>ID du bien:</dt>
                         						<dd><b><?=str_pad((int) $property->id,6,"0",STR_PAD_LEFT)?></b></dd>
                         						<dt>Date de Création:</dt>
                         						<dd><b><?=date('d-M-Y H:i:s',strtotime($property->date_create))?></b></dd>
                         					</dl>
                         					<hr>
                         					<dl class="dl-horizontal">
                         					<dt>Numéro:</dt>
                         					<dd><a href="#" id="number"  data-type="text" data-pk="<?=$property->id?>" data-url="<?=site_url()?>properties/modification" data-title="Numéro"><?=$property->number?></a></dd>
                         					<dt>Adresse:</dt>
                         					<dd><a href="#" id="address"  data-type="textarea" data-pk="<?=$property->id?>" data-url="<?=site_url()?>properties/modification" data-title="Adresse"><?=$property->address?></a></dd>
                         					<dt>Code Postal:</dt>
                         					<dd><a href="#" id="po"  data-type="text" data-pk="<?=$property->id?>" data-url="<?=site_url()?>properties/modification" data-title="Code Postale"><?=$property->po?></a></dd>
                         					<dt>Commune:</dt>
                         					<dd><a href="#" id="city"  data-type="text" data-pk="<?=$property->id?>" data-url="<?=site_url()?>properties/modification" data-title="Ville"><?=$property->city?></a></dd>
                         					<dt>Pays:</dt>
                         					<dd><a href="#" id="country"  data-type="text" data-pk="<?=$property->id?>" data-url="<?=site_url()?>properties/modification" data-title="Pays"><?=$property->country?></a></dd>
                         					<dt>N&deg; Boîte:</dt>
                         					<dd><a href="#" id="pobox"  data-type="text" data-pk="<?=$property->id?>" data-url="<?=site_url()?>properties/modification" data-title="Numéro"><?=$property->pobox?></a></dd>
                         					<dt>Etage:</dt>
                         					<dd><a href="#" id="floor"  data-type="text" data-pk="<?=$property->id?>" data-url="<?=site_url()?>properties/modification" data-title="Etage"><?=$property->floor?></a></dd>                         					
                         					</dl>
                         					<hr>
                         					<dl class="dl-horizontal">
                         					<dt>Type de bien:</dt>
                         					<dd><a href="#" id="category_id"  data-type="select" data-value="<?=$property->category_id?>" data-pk="<?=$property->id?>" data-url="<?=site_url()?>properties/modification" data-source="<?=site_url()?>properties/selectData/category"  title="Type"><?=$property->category->category?></a></dd>
                         					<dt>Superficie:</dt>
                         					<dd><a href="#" id="surface"  data-type="text" data-pk="<?=$property->id?>" data-url="<?=site_url()?>properties/modification" data-title="Superficie"><?=number_format($property->surface,2,',','')?></a> M&sup2;</dd>
                         					<dt>Prix:</dt>
                         					<dd><a href="#" id="price"  data-type="text" data-pk="<?=$property->id?>" data-url="<?=site_url()?>properties/modification" data-title="Prix" ><?=number_format($property->price,2,',','')?></a> €</dd>
                         					<dt>Type de contrat:</dt>
                         					<dd><a href="#" id="contract_id" data-type="select" data-prepend="non spécifié" data-pk="<?=$property->id?>" data-value="<?=$property->contract_id?>" data-url="<?=site_url()?>properties/modification" data-source="<?=site_url()?>properties/selectData/contract" title="Type de contrat"><?php if($property->contract_id) {echo $property->contract->contract;}else{ echo 'non spécifié';}?></a></dd>
                         					<dt>Transaction:</dt>
                         					<dd><a href="#" id="transaction_id" data-type="select" data-prepend="non spécifié" data-pk="<?=$property->id?>" data-value="<?=$property->transaction_id?>" data-url="<?=site_url()?>properties/modification" data-source="<?=site_url()?>properties/selectData/transaction" title="Transaction"><?php if($property->transaction_id) {echo $property->transaction->deal;}else{ echo 'non spécifié';}?></a></dd>
                         					</dl>
                         					<hr>
                         					<dl class="dl-horizontal">
                         						<dt>Description:</dt>
                         						<dd><a href="#" id="flash"  data-type="textarea" data-pk="<?=$property->id?>" data-url="<?=site_url()?>properties/modification" data-title="Adresse"><?=$property->flash?></a></dd>
                         					</dl>
                         					<hr>
                         					<dl class="dl-horizontal">
                         						<dt>Commentaire Interne:</dt>
                         						<dd><a href="#" id="flash_internal"  data-type="textarea" data-pk="<?=$property->id?>" data-url="<?=site_url()?>properties/modification" data-title="Commentaire Interne"><?=$property->flash_internal?></a></dd>
                         					</dl>
                         					<hr>
                         					<dl class="dl-horizontal">
                         						<dt>Representant:</dt>
                         						<dd><a href="#" id="aauth_user_id" data-type="select" data-prepend="non spécifié" data-pk="<?=$property->id?>" data-value="<?=$property->aauth_user_id?>" data-url="<?=site_url()?>properties/modification" data-source="<?=site_url()?>properties/selectData/agent" title="Représentant"><?php if($property->aauth_user_id) {echo $agent->name;}else{ echo 'non spécifié';}?></a></dd>
                         						<dt>Taux de commission:</dt>
                         						<dd><a href="#" id="commission" data-type="text" data-prepend="non spécifié" data-pk="<?=$property->id?>" data-value="<?=$property->commission?>" data-url="<?=site_url()?>properties/modification"  title="Commission"><?=number_format($property->commission,2,',','')?></a> %</dd>
                         					</dl>
                         					<hr>
                         					<dl class="dl-horizontal">
                         						<dt>Propriétaire:</dt>
                         						<dd><a href="#" id="customer_id"  data-type="select" data-prepend="non spécifié" data-pk="<?=$property->id?>" data-value="<?=$property->customer_id?>" data-url="<?=site_url()?>properties/modification" data-source="<?=site_url()?>properties/selectData/customer" title="Client"><?php if($property->customer_id) {echo $property->customer->lastname.' '.$property->customer->firstname;}else{ echo 'non spécifié';}?></a> | <button class="btn btn-xs btn-primary" data-toggle="modal" data-target="#addContact" data-backdrop="static"><i class="fa fa-plus-circle"></i> nouveau contact</button> </dd>
                         						
                         					</dl>
                         					<?php if($property->customer_id){?>
                         					<dl class="dl-horizontal">
                         					<dt>Date de Naissance:</dt>
                         					<dd><a href="#" id="birth" data-type="date" data-pk="<?=$property->customer->id?>" data-url="<?=site_url()?>customers/modification" data-title="Select date"><?php if($property->customer->birth){echo date('Y-m-d',strtotime($property->customer->birth));}?></a> <small>(format: aaaa-mm-jj )</small></dd>
                         					<dt>Langue:</dt>
                         					<dd><a href="#" id="lang_id" data-type="select" data-pk="<?=$property->customer->id?>" data-value="<?=$property->customer->lang_id?>" data-url="<?=site_url()?>customers/modification"data-source="<?=site_url()?>customers/selectData/lang"  data-title="Langues"><?=$property->customer->lang->lang?></a></dd>
                         					</dl>
                         					<dl class="dl-horizontal">
                         					<dt>Date de création:</dt>
                         						<dd><?=date('d-M-Y H:i',strtotime($property->customer->date_create))?></dd>
                         						<dt>Entreprise:</dt>
                         						<dd><a href="#" id="company"  data-type="text" data-pk="<?=$property->customer->id?>" data-url="<?=site_url()?>customers/modification" data-title="Entreprise"><?=$property->customer->company?></a></dd>
                         						<dt>Nom:</dt>
                         						<dd><a href="#" id="lastname"  data-type="text" data-pk="<?=$property->customer->id?>" data-url="<?=site_url()?>customers/modification" data-title="Nom"><?=$property->customer->lastname?></a></dd>
                         						<dt>Prénom:</dt>
                         						<dd><a href="#" id="firstname"  data-type="text" data-pk="<?=$property->customer->id?>" data-url="<?=site_url()?>customers/modification" data-title="Prénom"><?=$property->customer->firstname?></a></dd>
                         						<dt>Titre:</dt>
                         						<dd><a href="#" id="gender_id" data-type="select" data-pk="<?=$property->customer->id?>" data-value="<?=$property->customer->gender_id?>" data-url="<?=site_url()?>customers/modification" data-source="<?=site_url()?>customers/selectData/gender" data-title="Titre"><?=$property->customer->gender->gender?></a></dd>
                         						<dt>Téléphone:</dt>
                         						<dd><a href="#" id="telephone"  data-type="text" data-pk="<?=$property->customer->id?>" data-url="<?=site_url()?>customers/modification" data-title="GSM"><?=$property->customer->telephone?></a></dd>
                           						<dt>Email:</dt>
                         						<dd><a href="#" id="email"  data-type="text" data-pk="<?=$property->customer->id?>" data-url="<?=site_url()?>customers/modification" data-title="email"><?=$property->customer->email?></a></dd>
                         						<dt>Adresse:</dt>
                         						<dd><a href="#" id="address"  data-type="textarea" data-pk="<?=$property->customer->id?>" data-url="<?=site_url()?>customers/modification" data-title="Adresse"><?=$property->customer->address?></a></dd>                        						
                         					</dl>
                         					<hr>
                         					<dl class="dl-horizontal">
                         						<dt>Statut:</dt>
                         						<dd ><a href="#" id="statut_id"  data-type="select" data-pk="<?=$property->customer->id?>" data-value="<?=$property->customer->statut_id?>" data-url="<?=site_url()?>customers/modification" data-source="<?=site_url()?>customers/selectData/statut" data-title="Statut" class=" <?php if($property->customer->statut->statut =='Normal'){?>text-green<?php }elseif($property->customer->statut->statut =='Archivé'){?>text-light-blue<?php }else{?>text-red<?php }?>" ><?=$property->customer->statut->statut?></a></dd>
                         					</dl>
                         					<?php }?>
                         				</div>
                         			</div> 
                   				</div>
                   				<div class="clearfix"></div>
                                </div><!-- /.box-body -->                              
                            </div><!-- /.box -->                     
                    		</div>
                    		
					<div class="col-lg-6 col-xs-12">
						<div class="box box-primary">
							<div class="box-header">
							<i class="fa fa-picture-o"></i>
                                    <h3 class="box-title">photos du bien</h3>
                         	<div class="btn">
                        		 <a href="<?=site_url()?>gallery/upload/<?=$property->id?>" class="btn btn-primary"><i class="fa fa-upload"></i> téléchargez l'image</a>
					 		</div>
                         	</div>
                         			
						 <div class="box-body ">
                                	<div class="row">
                         		
                         			<div class="col-lg-12 col-xs-12">
                         				<?php foreach ($imgs as $p):?>
 <div class="post-box col-xs-12 col-sm-6 col-md-3 item_<?=$p->id?>">
    <div class="thumbnail">     
      <a class="thumbnail" href="<?=base_url()?>uploads/large/<?=$p->filename_l?>" title="<?=$p->filename_l?>"  data-gallery="">
       <img src="<?=base_url()?>uploads/thumbs/<?=$p->filename_s?>" alt="..." >
		</a>
      <div class="caption">
   		<p><button type="button" class="btn btn-danger btn-xs" role="button" onclick="deleteItem(<?=$p->id?>,'<?=$p->filename_s?>')"><i class="glyphicon glyphicon-trash"></i></button> |
   		<a  class="btn btn-danger btn-xs" href="<?=base_url()?>uploads/large/<?=$p->filename_l?>" target="_blank"><i class="fa fa-download"></i></a></p>
      </div>
    </div>
  </div>
	<?php endforeach;?>
                         			<div class="clearfix"></div>
                         			</div>
                         			</div>
                         </div>
					</div><!-- /.box -->
					</div>
					
					        <div class="col-lg-6 col-xs-12">
					 <div class="box box-primary">
                                <div class="box-header">
                                    <i class="ion ion-clipboard"></i>
                                    <h3 class="box-title">Statut Transaction</h3>
                                   
                                </div><!-- /.box-header -->
                                  <div class="box-body">
                                    <ul class="todo-list">
                                    <?php foreach ($transactions as $key=>$s):?>
                                    	 <li id="trans_<?=$key?>">
                                            <!-- drag handle -->
                                            <span class="handle">
                                                <i class="fa fa-ellipsis-v"></i>
                                                <i class="fa fa-ellipsis-v"></i>
                                            </span>                                            
                                             <!-- Emphasis label -->
                                            <span class="label label-default"> <?=date('d-M-Y',strtotime($s->date))?></span>                                  
                                            <!-- todo text -->
                                            <span class="text"><?=$s->procedure->procedure?></span>                                        
                                            <span><small>Détailles: {  <em><?=$s->flash?></em> }</small></span>
                                            <!-- General tools such as edit or delete-->
                                            <div class="tools">
                                               
                                                <i class="fa fa-trash-o" onclick = "deleteTrans('<?=$s->id?>','<?=$key?>')"></i>
                                            </div>
                                        </li>
                                    <?php endforeach;?>
                                      
                                    </ul>
                                </div><!-- /.box-body -->
                               <div class="box-footer clearfix no-border">
                               	<hr>
                               </div>
                                <div class="box-body">
                                <div class="row">
                                <div class="col-lg-8 col-xs-12">

                                	
                                  <form action="<?=site_url()?>properties/viewProperty/<?=$property->id?>" role="form" method="post">
       								<input type="hidden" name="property_id" value="<?=$property->id?>">
       								<input type="hidden" name="type" value="transaction">
      								<div class="form-group">
            							<label> * Statut Transaction:</label>
            							<select name="procedure_id" class="form-control">
            								<?php foreach($procedures as $procedure):?>
            									<option value="<?=$procedure->id?>"><?=$procedure->procedure?></option>           								
            								<?php endforeach;?>
            							</select>
            							</div>
           							 <div class="form-group">
									<label> * Date:</label>
               							 <div class='input-group date' id="date">
                             				<span class="input-group-addon datepickerbutton"><i class="fa fa-calendar"></i></span>
                    							<input type='text' class="form-control" data-date-format="DD-MM-YYYY" name="date" value="<?=set_value("date")?>"/>
                  
                    							<span class="input-group-addon" id="resetDate">
       					 							<span class="glyphicon glyphicon-remove"></span>
    											</span>
               									 </div>
               									 <?=form_error("date")?>
            						</div>
            						<div class="form-group">
            							<label>Description:</label>
            							<textarea rows="5" cols="3" class="form-control" name="flash" value=""></textarea>
            						</div>	
            						<hr>
               						<button type="submit" class="btn btn-primary btn-sm pull-right">Créer</button>
            						</form>
            						
                                </div>
                                </div>
                                </div>
                                <div class="box-footer clearfix no-border">
                           
                                </div>
                                <div class="clearfix"></div>
                      </div>
                      </div><!-- statut transaction finished -->
					
					<div class="col-lg-6 col-xs-12">
					 <div class="box box-primary">
                                <div class="box-header">
                                    <i class="ion ion-clipboard"></i>
                                    <h3 class="box-title">To Do List</h3>
                                   
                                </div><!-- /.box-header -->
                                <div class="box-body">
                                    <ul class="todo-list">
                                    <?php foreach ($doList as $key=>$l):?>
                                    	 <li id="list_<?=$key?>">
                                            <!-- drag handle -->
                                            <span class="handle">
                                                <i class="fa fa-ellipsis-v"></i>
                                                <i class="fa fa-ellipsis-v"></i>
                                            </span>  
                                            <!-- checkbox -->
                                            <input type="checkbox" value="" name=""/>          
                                             <!-- Emphasis label -->
                                            <span class="label bg-<?=$l->color?>"><i class="fa fa-clock-o"></i> <?=date('d-M-Y @ H:m',strtotime($l->date_start))?></span>                                  
                                            <!-- todo text -->
                                            <span class="text"><?=$l->content?></span>                                        
                                            <span><small>{ crée par <em><?=$l->auth_user->name?></em> }</small></span>
                                            <!-- General tools such as edit or delete-->
                                            <div class="tools">
                                               
                                                <i class="fa fa-trash-o" onclick = "deleteEvent('<?=$l->id?>','<?=$key?>')"></i>
                                            </div>
                                        </li>
                                    <?php endforeach;?>
                                      
                                    </ul>
                                </div><!-- /.box-body -->
                                <div class="box-footer clearfix no-border">
                                    <hr>
                                </div>
       
					
						 <div class="box-body ">
                                	<div class="row">
                         			<div class="col-lg-12 col-xs-12">
                         			
    <div style="height:75px;">
       <div class='col-lg-8 col-xs-12'>
        <?php if(isset($msg_error)){?>
                            	
                            	 <div class="box-header">
        <div class="alert alert-danger alert-dismissible" role="alert">
      
  <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
  <strong>Attentions!</strong> <?=$msg_error?></li></ol>
</div>
</div>
        <?php }?>
       <form action="<?=site_url()?>properties/viewProperty/<?=$property->id?>" role="form" method="post">
       <input type="hidden" name="property_id" value="<?=$property->id?>">
       <input type="hidden" name="agent_id" value="<?=$user->id?>">
       <input type="hidden" name="type" value="todolist">
            <div class="form-group">
				<label> * Début:</label>
                <div class='input-group date' id="start_date">
                             <span class="input-group-addon datepickerbutton">DE</span>
                    <input type='text' class="form-control" data-date-format="DD-MM-YYYY HH:mm" name="start_date" value="<?=set_value("start_date")?>"/>
                  
                    <span class="input-group-addon" id="resetStartDate">
       					 <span class="glyphicon glyphicon-remove"></span>
    				</span>
    				
                </div>
                <?=form_error("start_date")?>
            </div>
       
       
            <div class="form-group">
            <label>Fin (option):</label>
                <div class='input-group date' id='end_date'>
                 <span class="input-group-addon datepickerbutton">A</span>
                    <input type='text' class="form-control" data-date-format="DD-MM-YYYY HH:mm" name="end_date" value="<?=set_value("end_date")?>"/>
                     <span class="input-group-addon" id="resetEndDate">
       					 <span class="glyphicon glyphicon-remove"></span>
    				</span>
                   
                </div>
            </div>
            <div class="form-group">
            <lable><b>* Détailles:</b></lable>
            	<textarea name="content" value="<?=set_value("content")?>" class="form-control"></textarea>     
            	<?=form_error("content")?>       
            </div>
  
               <hr>
                 <!-- radio -->
                   <div class="form-group">
                      <label>
                      <span class="text-navy lead">
                        <i class="fa fa-square"></i>
                        </span><br>
                        <input type="radio" name="color" class="minimal" value="navy" checked/>                       
                         </label> 
                         <label>
                      <span class="text-green lead">
                        <i class="fa fa-square"></i>
                        </span><br>
                        <input type="radio" name="color" class="minimal" value="green"/>                       
                         </label> 
                          <label>
                      <span class="text-blue lead">
                        <i class="fa fa-square"></i>
                        </span><br>
                        <input type="radio" name="color" class="minimal" value="blue"/>                       
                         </label> 
                          <label>
                      <span class="text-yellow lead">
                        <i class="fa fa-square"></i>
                        </span><br>
                        <input type="radio" name="color" class="minimal" value="yellow"/>                       
                         </label> 
                         <label>
                      <span class="text-orange lead">
                        <i class="fa fa-square"></i>
                        </span><br>
                        <input type="radio" name="color" class="minimal" value="orange"/>                       
                         </label> 
                         <label>
                      <span class="text-aqua lead">
                        <i class="fa fa-square"></i>
                        </span><br>
                        <input type="radio" name="color" class="minimal" value="aqua"/>                       
                         </label> 
                         <label>
                         <span class="text-red lead">
                        <i class="fa fa-square"></i>
                        </span><br>
                        <input type="radio" name="color" class="minimal" value="red"/>                       
                         </label> 
                         <label>
                         <span class="text-fuchsia lead">
                        <i class="fa fa-square"></i>
                        </span><br>
                        <input type="radio" name="color" class="minimal" value="fuchsia"/>                       
                         </label> 
                         <label>
                         <span class="text-purple lead">
                        <i class="fa fa-square"></i>
                        </span><br>
                        <input type="radio" name="color" class="minimal" value="purple"/>                       
                         </label> 
                 </div>
               	<hr>
               	<button type="submit" class="btn btn-primary btn-sm pull-right">Créer</button>
              
            
            </form>
         </div>
    </div>
                         			
                       			</div>
                         </div>
                    </div>
                      <div class="box-footer clearfix no-border">
                                    <hr>
                                </div>
                    <div class="clearfix"></div>
                    </div>
                    
                    </div><!-- to do list finished -->
            
                           
                </section><!-- /.content -->
            </aside><!-- /.right-side -->
        </div><!-- ./wrapper -->
        
        <!-- The blueimp Gallery widget -->
<div id="blueimp-gallery" class="blueimp-gallery blueimp-gallery-controls" >
    <div class="slides"></div>
    <h3 class="title"></h3>
    <a class="prev">‹</a>
    <a class="next">›</a>
    <a class="close">×</a>
    <a class="play-pause"></a>
    <ol class="indicator"></ol>
</div>

<div id="deleteItem" class="modal fade " tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">×</button>
					<h4 id="myModalLabel">Action:</h4>
				</div>
				<div class="modal-body">Voulez-vous supprimer cette photo?</div>
				<div class="modal-footer">
					
					
				</div>
			</div>
		</div>
	</div>	
	<div id="deleteEvent" class="modal fade " tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">×</button>
					<h4 id="myModalLabel">Action:</h4>
				</div>
				<div class="modal-body"><p>Voulez-vous supprimer cet événement?</p></div>
				<div class="modal-footer">
					
					
				</div>
			</div>
		</div>
	</div>
		<div id="deleteTrans" class="modal fade " tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">×</button>
					<h4 id="myModalLabel">Action:</h4>
				</div>
				<div class="modal-body"><p>Voulez-vous supprimer cette transaction ?</p></div>
				<div class="modal-footer">
					
					
				</div>
			</div>
		</div>
	</div>
	<div id="addContact" class="modal fade " tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">×</button>
					<h4 id="myModalLabel">Nouveau contact:</h4>
				</div>
				<div class="modal-body">
					<form action="<?=site_url()?>properties/addContact" role="form">
					<input type="hidden" name="property_id" value="<?=$property->id?>">
						<div class="form-group" id="lastnameVal">
							<label>* Nom:</label>
							<input class="form-control" name="lastname" value="" type="text">
							<div class="error"></div>
						</div>
						<div class="form-group" id="firstnameVal">
							<label>* Prénom:</label>
							<input class="form-control" name="firstname" value="" type="text">
							<div class="error"></div>
						</div>
						
				
					<div class="clearfix"></div>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-primary btn-sm pull-right" onclick="form_validation()" id="addContactBtn" data-loading-text="traitement...">ajouter</button>
						</form>
				</div>
			</div>
		</div>
	</div>
        <script>
        
        	$(function(){
            		/* initilize x-editable on dd a */
        		    			
					$('dd a').editable({
						mode:'inline',
						emptytext:'- vide -',
						success:function(response, newValue){
							if(response=='customer_id' || response=='firstname' || response=='lastname' || response=='statut_id'){
								location.reload();
							}
						}
					})
					/* initilize datepicker */
					$('#start_date').datetimepicker();
		            $('#end_date').datetimepicker();
		            $('#date').datetimepicker({
						pickTime: false
					});
		            $("#start_date").on("dp.change",function (e) {
		               $('#end_date').data("DateTimePicker").setMinDate(e.date);
		            });
		            $("#end_date").on("dp.change",function (e) {
		               $('#start_date').data("DateTimePicker").setMaxDate(e.date);
		            });

		         
		            $('#addContact').on('hide.bs.modal', function (e) {
		   			 var firstname = $('input[name=firstname]').val('') ;
		   				var lastname = $('input[name=lastname]').val('') ;
		   				
		   			}) 
            	});
        	$("#resetStartDate").click(function () {
            	
                $('#start_date').data("DateTimePicker").setDate("");
            });
			$("#resetEndDate").click(function () {
            	
                $('#end_date').data("DateTimePicker").setDate("");
            });
			$("#resetDate").click(function () {
            	
                $('#date').data("DateTimePicker").setDate("");
            });
            
			function deleteEvent($id,$key)
			{
				
				$data = "'"+$id+"','"+$key+"'";
					$('#deleteEvent').modal({
            		  keyboard: false
            		});
					$("#deleteEvent .modal-footer").html(' <button type="button" class="btn btn-default" data-dismiss="modal">Non</button> <button id="deleteEventBtn" type="button" class="btn btn-danger" data-loading-text="traitement..." onclick = "do_delete('+$data+')" >OUI</button>');
				}
            function do_delete($id,$key)
            {
            	var btn = $("#deleteEventBtn");
          	    btn.button('loading');
				$.ajax({
					async:false,
					type:'POST',
					data:{id:$id},
					 url: '<?=site_url()?>properties/deleteEvent',
					success:function(data){
						btn.button('reset');
						$('#list_'+$key).remove();
						$("#deleteEvent .modal-body p").html('<span class="text-red">Cet événement a été effacé.</span>');
						$("#deleteEvent .modal-footer").html(' <button type="button" class="btn btn-default" data-dismiss="modal">Fermer</button> ');
						},
					dataType:'json'



					});
		  }

            function deleteTrans($id,$key)
			{
				
				$data = "'"+$id+"','"+$key+"'";
					$('#deleteTrans').modal({
            		  keyboard: false
            		});
					$("#deleteTrans .modal-footer").html(' <button type="button" class="btn btn-default" data-dismiss="modal">Non</button> <button id="deleteTransBtn" type="button" class="btn btn-danger" data-loading-text="traitement..." onclick = "do_deleteTrans('+$data+')" >OUI</button>');
				}

            function do_deleteTrans($id,$key)
            {
            	var btn = $("#deleteTransBtn");
          	    btn.button('loading');
				$.ajax({
					async:false,
					type:'POST',
					data:{id:$id},
					 url: '<?=site_url()?>properties/deleteTrans',
					success:function(data){
						btn.button('reset');
						$('#trans_'+$key).remove();
						$("#deleteTrans .modal-body p").html('<span class="text-red">Cette transaction a été effacé.</span>');
						$("#deleteTrans .modal-footer").html(' <button type="button" class="btn btn-default" data-dismiss="modal">Fermer</button> ');
						},
					dataType:'json'



					});
		  }
		 function form_validation(){
			var firstname = $('input[name=firstname]').val();
			var lastname = $('input[name=lastname]').val();
			var property_id = $('input[name=property_id]').val();
			if(firstname == '' && lastname == ''){
					$('#firstnameVal .error').html('<span class="text-red">Le champ prénom est requis.</span>');
					$('#lastnameVal .error').html('<span class="text-red">Le champ nom est requis.</span>');
				}else if(lastname == '' && firstname != ''){
					$('#lastnameVal .error').html('<span class="text-red">Le champ nom est requis.</span>');
					$('#firstnameVal .error').html('');
					}else if(lastname != '' && firstname == ''){
						$('#lastnameVal .error').html('');
						$('#firstnameVal .error').html('<span class="text-red">Le champ prénom est requis.</span>');
					}else{
						$('#firstnameVal .error').html('');
						$('#lastnameVal .error').html('');
						var btn = $("#addContactBtn");
		          	    btn.button('loading');
						$.ajax({
							async:false,
							type:"POST",
							url:"<?=site_url()?>properties/addContact",
							data:{
								firstname:firstname,
								lastname:lastname,
								property_id: property_id
								},
							success:function(d){
								btn.button('reset');
									if(d == true){
										$("#addContact .modal-body ").html('<span class="text-green">Le nouveau contact a été ajouté.</span>');
										$("#addContact .modal-footer").html(' <button type="button" class="btn btn-default" onclick="modalDismiss()">Fermer</button> ');
											}else{
												$("#addContact .modal-body ").html('<span class="text-red">Il y a une erreur.</span>');
												$("#addContact .modal-footer").html(' <button type="button" class="btn btn-default" data-dismiss="modal">Fermer</button> ');
												}
								},
							dataType:'json'
							});
					}
		 }

		function modalDismiss(){
			$('#addContact').modal().hide(function(){
					location.reload();
				});		  
			}

		function deleteItem(id, thumb) {
			$('#deleteItem .modal-body').html(
					'<p><img src="../../uploads/thumbs/' + thumb + '"></p>'
							+ '<p>Voulez-vous supprimer cette photo ?<br><b><small>'
							+ thumb + '</small></b></p>');
			$('#deleteItem .modal-footer')
					.html(
							'<button class="btn" data-dismiss="modal" aria-hidden="true">Non <i class="glyphicon glyphicon-ban-circle"></i></button>'
									+ '<button class="btn btn-danger" onclick="doDelete('
									+ id
									+ ')">Oui <i class="glyphicon glyphicon-trash"></i></button>');
			$('#deleteItem').modal({})
		}

		function doDelete($id) {
			var url = "<?=site_url()?>properties/deleteItem";
			
			$.post(url,{id : $id},function(data) {
								var arr = JSON.parse(data);
								if (arr.result == true) {
									$('#deleteItem .modal-body')
											.append(
													'<p class="alert alert-success">Cette photo a été supprimé.</p>');
									$('.row .item_' + $id).fadeOut();

								} else {
									$('#deleteItem .modal-body')
											.append(
													'<p class="alert alert-danger">Erreur, cette photo ne peut pas être supprimée.</p>');
								}

								$('#deleteItem .modal-footer')
										.html(
												'<button class="btn btn-primary" onclick="reloadCurrentPage()">ok</button>');
								
							});
		}

		function reloadCurrentPage()
		{
			location.reload();
		}	 
        </script>